package com.uenpay.im.invokeitems.login;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.qiyunxin.android.http.utils.Utils;
import com.qyx.android.utilities.DateUtils;
import com.socks.library.KLog;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

import static com.uenpay.im.configuration.APIConfiguration.getSmsBaseUrl;

/**
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class ResendCaptchaInvokeItem extends HttpInvokeItem {
    private static final String TAG = "ResendCaptchaInvokeItem";

    public class ResendCaptchaResult {
        public int status;
        public String msg;
        public String vercode;
    }

    public ResendCaptchaResult getOutput() {
        return (ResendCaptchaResult) GetResultObject();
    }

    /**
     * 获取验证码
     *
     * @param mobilePhone
     */
    public ResendCaptchaInvokeItem(String mobilePhone, String type) {
        String url = getSmsBaseUrl() + "verifycode/send?phones=" + mobilePhone + "&type=" + type + "&channel=custom";
        KLog.d(TAG, "[ResendCaptchaInvokeItem] url=" + url);
        SetUrl(url);
    }

    @Override
    protected Object DeserializeResult(String responseBody) {
        ResendCaptchaResult result = new ResendCaptchaResult();
        try {
            JSONObject json = new JSONObject(responseBody);
            result.status = json.optInt("status");
            result.msg = json.optString("msg");
            if (json.has("data")) {
                JSONObject js = json.optJSONObject("data");
                if (js == null) {
                    return result;
                }
                result.vercode = js.optString("vercode");
            }
        } catch (JSONException e) {
            e.printStackTrace();
            return result;
        }

        return result;
    }
}
